import { faker } from '@faker-js/faker';

export interface UserInfo {
  id: number;
  password: string;
  realName: string;
  roles: string[];
  username: string;
  homePath?: string;
}

export const MOCK_USERS: UserInfo[] = [
  {
    id: 0,
    password: '123456',
    realName: 'Vben',
    roles: ['super'],
    username: 'vben',
  },
  {
    id: 1,
    password: '123456',
    realName: 'Admin',
    roles: ['admin'],
    username: 'admin',
    homePath: '/workspace',
  },
  {
    id: 2,
    password: '123456',
    realName: 'Jack',
    roles: ['user'],
    username: 'jack',
    homePath: '/analytics',
  },
];

export const MOCK_CODES = [
  // super
  {
    codes: ['AC_100100', 'AC_100110', 'AC_100120', 'AC_100010'],
    username: 'vben',
  },
  {
    // admin
    codes: ['AC_100010', 'AC_100020', 'AC_100030'],
    username: 'admin',
  },
  {
    // user
    codes: ['AC_1000001', 'AC_1000002'],
    username: 'jack',
  },
];

const dashboardMenus = [
  {
    component: 'BasicLayout',
    meta: {
      order: -1,
      title: 'page.dashboard.title',
    },
    name: 'Dashboard',
    path: '/',
    redirect: '/analytics',
    children: [
      {
        name: 'Analytics',
        path: '/analytics',
        component: '/dashboard/analytics/index',
        meta: {
          affixTab: true,
          title: 'page.dashboard.analytics',
        },
      },
      {
        name: 'Workspace',
        path: '/workspace',
        component: '/dashboard/workspace/index',
        meta: {
          title: 'page.dashboard.workspace',
        },
      },
    ],
  },
];

const createDemosMenus = (role: 'admin' | 'super' | 'user') => {
  const roleWithMenus = {
    admin: {
      component: '/demos/access/admin-visible',
      meta: {
        icon: 'mdi:button-cursor',
        title: 'demos.access.adminVisible',
      },
      name: 'AccessAdminVisibleDemo',
      path: '/demos/access/admin-visible',
    },
    super: {
      component: '/demos/access/super-visible',
      meta: {
        icon: 'mdi:button-cursor',
        title: 'demos.access.superVisible',
      },
      name: 'AccessSuperVisibleDemo',
      path: '/demos/access/super-visible',
    },
    user: {
      component: '/demos/access/user-visible',
      meta: {
        icon: 'mdi:button-cursor',
        title: 'demos.access.userVisible',
      },
      name: 'AccessUserVisibleDemo',
      path: '/demos/access/user-visible',
    },
  };

  return [
    {
      component: 'BasicLayout',
      meta: {
        icon: 'ic:baseline-view-in-ar',
        keepAlive: true,
        order: 1000,
        title: 'demos.title',
      },
      name: 'Demos',
      path: '/demos',
      redirect: '/demos/access',
      children: [
        {
          name: 'AccessDemos',
          path: '/demosaccess',
          meta: {
            icon: 'mdi:cloud-key-outline',
            title: 'demos.access.backendPermissions',
          },
          redirect: '/demos/access/page-control',
          children: [
            {
              name: 'AccessPageControlDemo',
              path: '/demos/access/page-control',
              component: '/demos/access/index',
              meta: {
                icon: 'mdi:page-previous-outline',
                title: 'demos.access.pageAccess',
              },
            },
            {
              name: 'AccessButtonControlDemo',
              path: '/demos/access/button-control',
              component: '/demos/access/button-control',
              meta: {
                icon: 'mdi:button-cursor',
                title: 'demos.access.buttonControl',
              },
            },
            {
              name: 'AccessMenuVisible403Demo',
              path: '/demos/access/menu-visible-403',
              component: '/demos/access/menu-visible-403',
              meta: {
                authority: ['no-body'],
                icon: 'mdi:button-cursor',
                menuVisibleWithForbidden: true,
                title: 'demos.access.menuVisible403',
              },
            },
            roleWithMenus[role],
          ],
        },
      ],
    },
  ];
};

export const MOCK_MENUS = [
  {
    menus: [...dashboardMenus, ...createDemosMenus('super')],
    username: 'vben',
  },
  {
    menus: [...dashboardMenus, ...createDemosMenus('admin')],
    username: 'admin',
  },
  {
    menus: [...dashboardMenus, ...createDemosMenus('user')],
    username: 'jack',
  },
];

// 生成语料库列表模拟数据
const generateCorpusData = () => {
  return Array.from({ length: 20 }, (_, index) => {
    const createdAt = faker.date
      .between({
        from: new Date('2023-01-01'),
        to: new Date(),
      })
      .getTime();
    const updatedAt = faker.date
      .between({
        from: new Date(createdAt),
        to: new Date(),
      })
      .getTime();

    return {
      category: faker.helpers.arrayElement([
        '技术',
        '商业',
        '教育',
        '娱乐',
        '健康',
        '体育',
        '新闻',
        '科学',
      ]),
      content: faker.lorem.paragraphs(faker.number.int({ min: 1, max: 5 })),
      createdAt,
      id: index + 1,
      status: faker.helpers.weightedArrayElement([
        { weight: 0.1, value: 0 }, // 草稿
        { weight: 0.7, value: 1 }, // 已发布
        { weight: 0.2, value: 2 }, // 归档
      ]),
      title: faker.lorem.sentence({ min: 3, max: 8 }),
      updatedAt,
    };
  });
};

export const MOCK_CORPUS_LIST_DATA = generateCorpusData();

// 生成角色列表模拟数据
const generateRoleData = () => {
  return Array.from({ length: 20 }, (_, index) => {
    const createdAt = faker.date
      .between({
        from: new Date('2023-01-01'),
        to: new Date(),
      })
      .getTime();
    const updatedAt = faker.date
      .between({
        from: new Date(createdAt),
        to: new Date(),
      })
      .getTime();

    return {
      id: index + 1,
      createdAt,
      updatedAt,
      status: faker.helpers.weightedArrayElement([
        { weight: 0.1, value: 0 }, // 禁用
        { weight: 0.9, value: 1 }, // 启用
      ]),
      name: faker.helpers.arrayElement([
        '超级管理员',
        '管理员',
        '普通用户',
        '访客',
        '编辑员',
        '审核员',
        '运营专员',
        '客服专员',
        '财务专员',
        '技术专员',
        '产品经理',
        '项目经理',
        '销售经理',
        '市场专员',
        '人事专员',
        '仓库管理员',
        '物流专员',
        '质检员',
        '培训师',
        '顾问',
      ]),
      defaultRouter: faker.helpers.arrayElement([
        'dashboard',
        'user',
        'system',
        'content',
        'order',
        'product',
        'report',
        'setting',
      ]),
      remark: faker.helpers.maybe(
        () => faker.lorem.sentence({ min: 5, max: 12 }),
        { probability: 0.7 },
      ),
      sort: faker.number.int({ min: 1, max: 100 }),
    };
  });
};

export const MOCK_ROLE_LIST_DATA = generateRoleData();

// 生成部门列表模拟数据

const generateDepartmentData = () => {
  return Array.from({ length: 20 }, (_, index) => {
    const createdAt = faker.date
      .between({
        from: new Date('2023-01-01'),
        to: new Date(),
      })
      .getTime();
    const updatedAt = faker.date
      .between({
        from: new Date(createdAt),
        to: new Date(),
      })
      .getTime();

    return {
      id: index + 1,
      createdAt,
      updatedAt,
      status: faker.helpers.weightedArrayElement([
        { weight: 0.1, value: 0 }, // 禁用
        { weight: 0.9, value: 1 }, // 启用
      ]),
      sort: faker.number.int({ min: 1, max: 100 }),
      name: faker.lorem.word(faker.number.int({ min: 2, max: 4 })),
      ancestors: null,
      leader: faker.person.fullName(),
      phone: faker.phone.number(),
      email: faker.internet.email(),
      remark: faker.helpers.maybe(
        () => faker.lorem.sentence({ min: 5, max: 12 }),
        { probability: 0.7 },
      ),
      parentId: faker.number.int({ min: 0, max: 20 }),
    };
  });
};
export const MOCK_DEPARTMENT_LIST_DATA = generateDepartmentData();

export const MOCK_USER_LIST_DATA = [
  {
    id: 11,
    createdAt: 1_747_964_270_869,
    updatedAt: 1_750_650_542_850,
    status: 0,
    username: '肯哥',
    nickname: '1111',
    password: '',
    description: '111',
    homePath: '/hone',
    mobile: '18606035485',
    email: '332@qq.com',
    avatar: null,
    departmentId: 1,
    roleIds: [],
  },
  {
    id: 9,
    createdAt: 1_747_814_512_556,
    updatedAt: 1_747_814_525_364,
    status: 1,
    username: '用户-1[角色客服](勿删)',
    nickname: '111',
    password: '',
    description: '111',
    homePath: '/dashboard',
    mobile: '111111111111',
    email: '11111@qq.com',
    avatar: null,
    departmentId: 1,
    positionId: [3],
    roleIds: [2, 3],
  },
  {
    id: 8,
    createdAt: 1_747_378_177_346,
    updatedAt: 1_747_897_122_055,
    status: 1,
    username: '用户-2[角色客服](勿删)',
    nickname: '1212',
    password: '',
    description: '111',
    homePath: '/dashboard',
    mobile: '11',
    email: '111@qq.com',
    avatar: null,
    departmentId: 1,
    positionId: [1],
    roleIds: [1, 3, 4],
  },
  {
    id: 4,
    createdAt: 1_747_043_333_508,
    updatedAt: 1_747_906_291_078,
    status: 0,
    username: '212',
    nickname: '1212',
    password: '',
    description: '',
    homePath: '11',
    mobile: '111',
    email: 'j',
    avatar: '',
    departmentId: 1,
    roleIds: [],
  },
  {
    id: 1,
    createdAt: 1_747_187_075_160,
    updatedAt: 1_753_235_629_230,
    status: 1,
    username: 'yiyouju',
    nickname: 'labubu',
    password: '',
    description: '9999',
    homePath: '/dashboard',
    mobile: '16666666666',
    email: '22@qq.com',
    avatar: null,
    departmentId: 1,
    positionId: [1],
    roleIds: [1, 3],
  },
];
